package pl.multimedialne.carculator.gui.dataContainers;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Calendar;
import static java.util.Calendar.MONTH;
import java.util.Date;

import android.R.string;

public class CostsDataContainer  implements Serializable{
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	public ArrayList<Cost> costs;
	
	public CostsDataContainer()
	{
		costs = new ArrayList<Cost>();
	}
	
	public void AddCost(Date date, String description, double price)
	{
		costs.add(new Cost(date, description, price));
	}
	
	public double CalculateMonthCosts()
	{
		double sum = 0.0;
		Calendar calendar = Calendar.getInstance();
		calendar.add( MONTH, -1);
		for (Cost cost : costs){
			if (cost.date.compareTo(calendar.getTime()) > 0)
			sum += cost.price;
		}
		return sum;
	}
	
	public double CalculateYearCosts()
	{
		double sum = 0.0;
		Date date = new Date();
		date.setYear(date.getYear() - 1);
		for (Cost cost : costs){
			if (cost.date.compareTo(date) > 0)
			sum += cost.price;
		}
		return sum;
	}
	
	public double CalculateOverallCosts()
	{
		double sum = 0.0;
		for (Cost cost : costs){
			sum += cost.price;
		}
		return sum;
	}
}
